package cn.relx.basic.listener;

import cn.relx.pet.mapper.SearchMasterMsgMapper;
import org.apache.rocketmq.client.producer.LocalTransactionState;
import org.apache.rocketmq.client.producer.TransactionListener;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.common.message.MessageExt;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class TranListener implements TransactionListener {
    @Autowired
    private SearchMasterMsgMapper searchMasterMsgMapper;

    @Override
    public LocalTransactionState executeLocalTransaction(Message message, Object obj) {
        try {
            System.out.println("我这边执行成功了!");
            System.out.println(obj);
            return LocalTransactionState.COMMIT_MESSAGE;
        } catch (Exception e) {
            e.printStackTrace();
            return LocalTransactionState.ROLLBACK_MESSAGE;
        }
    }

    @Override
    public LocalTransactionState checkLocalTransaction(MessageExt messageExt) {
        System.out.println("我这边执行失败了!");
        return LocalTransactionState.ROLLBACK_MESSAGE;
    }
}
